package com.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.core.sym.Name;
import com.springcloud.entity.Dept;

@RestController
public class DeptController_Consumer {
	//public static final String REST_URL_PREFIX="http://localhost:8001";
	public static final String REST_URL_PREFIX="http://MICROSERVICECLOUD-DEPT";
	@Autowired
private RestTemplate restTemplate;


	@RequestMapping("/consumer/n")
	public String  Name() {
		return "发了";
	}
	@RequestMapping("/consumer/dept/add")
	public boolean add(Dept dept) {
		return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add", dept, Boolean.class);
	}
	
	@RequestMapping( "/consumer/dept/get/{deptno}")
	public Dept get(@PathVariable("deptno")int deptno) {
		return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+deptno, Dept.class);
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping("/consumer/dept/list")
	public  List<Dept> list() {
		return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
	}
}
